home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 September / LiquidLibrary 2005 Sep - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_dps.ps < prev    next >
Text File  |  2003-01-03  |  7KB  |  193 lines

  1. %    Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Initialization file for Display PostScript functions.
  7.  
  8. % ------ Contexts ------ %
  9.  
  10. % To create a context with private local VM, we use the .localfork
  11. % operator to actually create the context, the new VM, and an empty
  12. % userdict, and then we call the .initlocaldicts procedure to make
  13. % local copies of the initial contents of the dictionaries in local VM.
  14. % savedlocaldicts in systemdict is a global read-only dictionary whose
  15. % elements are global read-only copies of these initial contents;
  16. % we just copy its elements into local VM and install them in systemdict.
  17. % userdict and internaldict require special handling.
  18.  
  19. % Switching between contexts with different local VMs requires
  20. % changing the bindings in systemdict that reference local objects.
  21. % For this purpose, each userdict has an entry called localdicts
  22. % which holds the local copies of the elements of savedlocaldicts,
  23. % plus internaldict.  The context switching code in the interpreter
  24. % effectively copies this dictionary into systemdict.
  25. % NOTE: the name localdicts is known to the interpreter.
  26.  
  27. % Switching between contexts also requires resetting the user parameters.
  28. % The interpreter records the value of userparams (a local dictionary
  29. % referenced from systemdict) for each context, and uses it for this.
  30. % See gs_lev2.ps for more details.
  31. % NOTE: the name userparams is known to the interpreter.
  32.  
  33. % Save copies of local dictionaries at the end of system initialization.
  34. % Also save the initial gstate.
  35. /.savelocalstate {
  36.   .currentglobal true .setglobal
  37.   //systemdict /savedlocaldicts mark //systemdict {
  38.     dup gcheck {
  39.       pop pop
  40.     } {
  41.       dup type /dicttype eq {
  42.         % Save a copy of this dictionary in global VM.
  43.     dup maxlength dict .copydict readonly
  44.       } {
  45.     pop pop
  46.       } ifelse
  47.     } ifelse
  48.   } forall .dicttomark readonly put
  49.         % Create localdicts for the current context.
  50.   false .setglobal
  51.   userdict /localdicts mark savedlocaldicts {
  52.     pop dup load
  53.   } forall /internaldict dup load
  54.   .dicttomark readonly put
  55.         % Save a copy of the initial gstate.
  56.   true .setglobal
  57.   //systemdict /savedinitialgstate gstate readonly put
  58.   .setglobal
  59. } .bind def
  60.  
  61. % Initialize local dictionaries and gstate when creating a new context.
  62. % Note that until this completes, we are in the anomalous situation of
  63. % having systemdict point to dictionaries that are in a non-current
  64. % local VM.  Because of this, we turn off garbage collection temporarily.
  65. /.copylocal {        % <name> <dict> .copylocal <name> <dict'>
  66.         % Copy a dictionary to the current (local) VM,
  67.         % and make it read-only if its current definition is.
  68.   dup maxlength dict .copydict
  69.   1 index load wcheck not { readonly } if
  70. } .bind def
  71. % When this is called, the dictionary stack is in its initial state,
  72. % and there is (anomalously) only one gstate on the gstate stack.
  73. /.initlocaldicts {        % - .initlocaldicts -
  74.   -2 vmreclaim
  75.   .currentglobal //systemdict begin
  76.   false .setglobal
  77.         % Since localdicts doesn't exist yet, references from
  78.         % systemdict to local objects won't get restored if
  79.         % a context switch happens in this code.  Therefore,
  80.         % until localdicts is defined, we have to keep all our
  81.         % state on the operand stack.
  82.  
  83.         % Acquire userdict.
  84.         %****** WRONG IF NON-STANDARD INITIAL DSTACK ******
  85.   countdictstack array dictstack
  86.    { dup gcheck not { exit } if pop } forall
  87.         % Create localdicts with a local copy of each dictionary,
  88.         % except for userdict and userparams, which just need
  89.         % to be filled in.
  90.   mark savedlocaldicts {
  91.     1 index /userdict eq {
  92.         % Stack: userdict mark ... /userdict inituserdict
  93.       counttomark 1 add index .copydict
  94.     } {
  95.       1 index /userparams eq {
  96.         % Stack: userdict mark ... /userparams inituserparams
  97.     userparams .copydict
  98.       } {
  99.     .copylocal
  100.       } ifelse
  101.     } ifelse
  102.   } forall /internaldict dup .makeinternaldict .makeoperator
  103.   .dicttomark readonly /localdicts exch put
  104.         % localdicts is now defined in userdict.
  105.         % Copy the definitions into systemdict.
  106.   localdicts { .forcedef } forall
  107.         % Set the user parameters.
  108.   userparams readonly .setuserparams
  109.         % Establish the initial gstate(s).
  110.   /savedinitialgstate .systemvar setgstate gsave
  111.         % Wrap up.
  112.   end .setglobal
  113. } odef
  114.  
  115. % Check whether an object is a procedure.
  116. /.proccheck {            % <obj> .proccheck <bool>
  117.   dup xcheck
  118.   exch type dup /arraytype eq exch /packedarraytype eq or and
  119. } bind def
  120.  
  121. % Create a context with private local VM.
  122. % The .localfork operator does all the work, but we must ensure that
  123. % .initlocaldicts gets called when the new context starts up.
  124. /localfork {            % <mark> <obj1> ... <objN> <proc>
  125.                 %   <stdin|null> <stdout|null>
  126.                 %   localfork <context>
  127.   .currentglobal true .setglobal 3 index
  128.   dup .proccheck not {
  129.     pop .setglobal /localfork cvx /typecheck signalerror
  130.   } if
  131.   {exec .initlocaldicts} aload pop
  132.   3 1 roll 3 packedarray cvx
  133.   4 1 roll 5 -1 roll pop .setglobal .localfork
  134. } odef
  135.  
  136. % Fork a context that shares VM.  The .fork operator creates an empty
  137. % userparams dictionary for the context, but we still need to initialize
  138. % this dictionary when the new context starts up.
  139. /.postfork {        % - .postfork -
  140.     % Initialize the user parameters.
  141.   savedlocaldicts /userparams get userparams .copydict readonly pop
  142. } odef
  143. /fork {            % <mark> <obj1> ... <objN> <proc> fork <context>
  144.   .currentglobal false .setglobal 1 index
  145.   dup .proccheck not {
  146.     pop .setglobal /fork cvx /typecheck signalerror
  147.   } if
  148.   {exec .postfork} aload pop
  149.   3 1 roll 3 packedarray cvx
  150.   3 1 roll exch pop .setglobal .fork
  151. } odef
  152.  
  153. % ------ Halftone phase ------ %
  154.  
  155. /sethalftonephase {        % <x> <y> sethalftonephase -
  156.   -1 2 index 2 index .setscreenphase pop pop
  157. } odef
  158. /currenthalftonephase {        % - currenthalftonephase <x> <y>
  159.   0 .currentscreenphase
  160. } odef
  161.  
  162. % ------ Device-source images ------ */
  163.  
  164. .imagetypes 2 /.image2 load put
  165.  
  166. % ------ Device information ------ %
  167.  
  168. /.deviceinfodict mark
  169.   /Colors null /GrayValues null /RedValues null /GreenValues null
  170.   /BlueValues null /ColorValues null
  171. .dicttomark readonly def
  172. /deviceinfo {            % - deviceinfo <dict>
  173.   currentdevice //.deviceinfodict .getdeviceparams .dicttomark readonly
  174. } odef
  175.  
  176. % The current implementation allocates a 2-element array each time.
  177. % Perhaps we should change this to 2 separate parameters for X and Y?
  178. /.wtdict mark
  179.   /wtranslation null
  180. .dicttomark readonly def
  181. /wtranslation {            % - wtranslation <x> <y>
  182.   currentdevice //.wtdict .getdeviceparams exch pop exch pop aload pop
  183. } odef
  184. currentdict /.wtdict .undef
  185.  
  186. % ------ View clipping ------ %
  187.  
  188. /rectviewclip {            % <x> <y> <width> <height> rectviewclip -
  189.                 % <numarray|numstring> rectviewclip -
  190.   newpath .rectappend viewclip
  191. } odef
  192.